package com.zjitc.p3.demo1;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-2018/3/13 15:58
 * @description:
 */
@Aspect // 切面类
public class AspectDemo {

  @Pointcut("execution(* com.zjitc.p3.demo1.A.a())")
  public void pointcutA() {}

  @Pointcut("execution(* com.zjitc.p3.demo1.A.b())")
  public void pointcutB() {}
  /**
   * 1. Pointcut
   * 2. Advice
   */
  @Before("pointcutA()")
  public void beforeA() {
    System.out.println("init before a");
  }

  @After("pointcutA()")
  public void afterA() { System.out.println("destroy after a");}

  @AfterThrowing("pointcutB()")
  public void whenException() {
    System.out.println("error happened");
  }

  @Around("execution(* com.zjitc.p3.demo1.A.c())")
  public void around(ProceedingJoinPoint jp) throws Throwable {
    System.out.println(jp.getSignature().getName());
    jp.proceed();
  }
}

// AspectDemo.beforeA();
// A.a();
